<?
session_start();
include("config.php");
if ($_SESSION['admin']!="OK")
{
	echo "<script language='javascript'>alert('Log in Please!');window.location.href='login.php';</script>";
	exit;
}
else
{ 
	if ($_POST["actions"]=="1")
	{    
		$conn=mysql_connect($host,$user,$password);
		mysql_select_db($db);
		mysql_query("SET NAMES UTF8");
		$choice=addslashes(trim($_POST["choice"]));
		if (empty($choice))
		{
			echo "<script language='javascript'>alert('The option can not be empty!');history.go(-1);</script>";
		}
		else
		{
			$query="insert into vote_choice(choice,titleid,IsOptions) values('".$choice."',".$_POST["titleid"].",'".$_POST["IsOptions"]."')";
			$result=mysql_query($query);
			echo "<meta http-equiv='refresh' content='0;url=addchoice.php?id=".$_POST["titleid"]."'>";
		}
	}
	else
	{
		$conn=mysql_connect($host,$user,$password);
		mysql_select_db($db);
		mysql_query("SET NAMES UTF8");
		$sql="select * from vote_title where id=".$_GET['id'];
		$result=mysql_query($sql);
		$row=mysql_fetch_array($result);
		if ($row["options"]=="a")
		{
			$ch="Single";
		}
		else
		{
			$ch="Multipul";
		}
	}
} 
?>
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Questionnaire Survey System Management</title> 
<link href="main.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function checkdel()
{
	if(!confirm('Confirm to Delete?')) 
		return false;
}
</script>
</head> 
<body>
<div id=main>
	<div class=title>Add Vote Topic Management</div> <div id="menu">
	<ul>
		<li><a href='admin.php'>Administraction</a></li>
		<li><a href="editadmin.php">Your Account</a></li>
		<li><a href="addtitle.php" class="top">Add vote topic</a></li>
		<li><a href="showvote.php" target="_blank">Vote result</a></li>
		<li><a href="javascript:$msg=confirm('Are u sure to clean the result?');$msg?window.location.href='clearResult.php':history.go(0);">Delete Result</a></li>
		<li><a href="loginout.php">Log out</a></li>
		<li><a href="index.php" target="_blank">Home</a></li>
	</ul>
</div>
<div id=addch>
<div class=bt>Vote topic</div>
<div class=btnr><font color=red><? echo strlen(stripslashes($row["title"]))>101?chinesesubstr(stripslashes($row["title"]),0,100)."...":stripslashes($row["title"]);?></font></div>
<div class=bt>Choice Type</div>
<div class=xzlx><?=$ch;?></div>
</div>
<div id=chlist>
<div class=nr>Already Existed Choice</div>
<div class=ch>Default or not</div>
<div class=sz>Set</div>
</div>
<?
$sql1="select * from vote_choice where titleid=".$_GET["id"];
$result1=mysql_query($sql1);
if (@mysql_num_rows($result1)==0)
{
	echo "<center><font color=red>No option till now!</font></center>";
}
else
{
	while ($row1=mysql_fetch_array($result1))
	{
		if ($row1["IsOptions"]=="a")
			$de="Yes";
		else
			$de="No";
?>
		<div class="chlist2">
		<div class=nr1><?=stripslashes($row1["choice"]);?></div>
		<div class=ch1><?=$de;?></div>
		<div class=sz1><a href="editchoice.php?id=<?=$row1["id"]?>">Edit</a> <a href="delchoice.php?id=<?=$row1["id"]?>" onClick="return checkdel()" >Delete</a></div>
		</div> 
<?
	}
}
?> 

<form name="addch" method="post" action="">
<div id=chlist>
<div class=nr>Add Option</div>
<div class=ch>Default?</div>
<div class=sz>Action</div>
</div>
<div class="chlist2">
<div class=nr1><input name="choice" type="text" class="inputs" id="choice" size="90"></div>
<div class=ch1><input type="radio" name="IsOptions" value="a">Yes<input name="IsOptions" type="radio" value="b" checked>No</div>
<div class=sz1><input type="submit" name="Submit" value="submit" class="inputs"><input name="titleid" type="hidden" id="titleids" value="<?=$_GET["id"];?>"><input name="actions" type="hidden" id="actions" value="1"></div>
</div>
<div class="chlist3"><font color=red>Each topic only can have one default option, or the system can be wrong!</font></div>
</form>
</div>
<br />
<center>Copyright@FengYL</center>
</body>
</html>
